package com.xuecheng.content.controller;

import com.xuecheng.api.content.model.dto.TeachplanDTO;
import com.xuecheng.api.content.model.vo.TeachPlanVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.TeachPlanConvert;
import com.xuecheng.content.service.TeachPlanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
public class TeachPlanController {
    @Autowired
    private TeachPlanService teachPlanService;

    @GetMapping("teachplan/{courseBaseId}/tree-nodes")
    public TeachplanDTO queryTeachPlanByCourseId(@PathVariable("courseBaseId") Long courseId){

        //获取公司id
        Long companyId = SecurityUtil.getCompanyId();
        //调用方法
        TeachplanDTO dto = teachPlanService.queryTeachPlanByCourseId(courseId, companyId);

        return dto;

    }

    @PostMapping("teachplan")
    public TeachplanDTO createOrModifyTeachPlan(@RequestBody TeachPlanVO vo){
        //获取公司id
        Long companyId = SecurityUtil.getCompanyId();
        //将vo转为dto
        TeachplanDTO dto = TeachPlanConvert.INSTANCE.vo2dto(vo);
        //调用方法
        TeachplanDTO teachplanDTO = teachPlanService.createOrModifyTeachPlan(dto, companyId);

        return teachplanDTO;

    }
}
